package com.example.demo.rx.cat;

import java.net.URL;
import java.util.List;

public class ApiWrapper3Job {
    Api api;
    public AsyncJob<List<Cat>> queryCats(String query) {
        return new AsyncJob<List<Cat>>() {
            @Override
            public void start(Callback<List<Cat>> catsCallback) {
                api.queryCats(query, new Api.CatsQueryCallback() {
                    @Override
                    public void onCatListReceived(List<Cat> cats) {
                        catsCallback.onResult(cats);
                    }

                    @Override
                    public void onQueryFailed(Exception e) {
                        catsCallback.onError(e);
                    }
                });
            }
        };
    }

    public AsyncJob<URL> store(Cat cat) {
        return new AsyncJob<URL>() {
            @Override
            public void start(Callback<URL> urlCallback) {
                api.store(cat, new Api.StoreCallback() {
                    @Override
                    public void onCatStored(URL url) {
                        urlCallback.onResult(url);
                    }

                    @Override
                    public void onStoreFailed(Exception e) {
                        urlCallback.onError(e);
                    }
                });
            }
        };
    }
}
